//
//  MYTabBarItem.swift
//  MYWeibo
//
//  Created by Magic Yu on 16/4/22.
//  Copyright © 2016年 Magic Yu. All rights reserved.
//

import UIKit

class MYTabBarItem: UITabBarItem {

     override var badgeValue: String? {
        didSet {
        let target = self.valueForKey("_target") as! MYMainViewController
            //遍历tabBar的子视图
            for subview in target.tabBar.subviews {
                if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                    for v in subview.subviews {
                        if v.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                            for bgView in v.subviews {
                                if bgView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                    //print("zhongyuzhaodaoni")
                                    //print(bgView)
                                    //通过KVC 来设置成员变量 打断点 通过调试台查看成员变量
                                    bgView.setValue(UIImage(named: "main_badge"), forKey: "_image")
                                }
                            }
                        }
                    }
                }
            }

            
        }
        
    }
    
}
